<?php

/*
 * This validates admin and users.
 */

class Validations_User {

    function __construct() {
        
    }

    public function validateUser($userType) {
        if ($this->hasidentity()) {
            $data = $this->getInstanceData();
            echo $userTypeId = $data->user_type;
            switch ($userType) {
                case 'admin':
                    if($userTypeId!=1){                                                
                        $this->clearInstance();
                        return false;
                    }
                    break;
                case 'user':
                    if($userTypeId!=2){                        
                        $this->clearInstance();
                    }
                    break;
                default:
                    break;
            }
        } else {
            return false;
        }
    }

    public function hasidentity() {
        if (Zend_Auth::getInstance()->hasIdentity()) {
            return true;
        } else {
            return false;
        }
    }

    public function getInstanceData() {
        $auth = Zend_Auth::getInstance();
        return $auth->getIdentity();
    }
    
    public function getUserTypeId() {
        $data = $this->getInstanceData();       
        return $data->user_type;
    }
    
    public function getUserId() {
        $data = $this->getInstanceData();
        return $data->id;
    }
    
    public function getUserName() {
        $data = $this->getInstanceData();
        return $data->name;
    }
    
    
    
    public function clearInstance(){
            Zend_Auth::getInstance()->clearIdentity();
    }
    
    

  
}

